RTCRtpReceiver.getStats() in blink added behind flag. This exposes RTCRtpReceiver.getStats() in JavaScript (behind flag) which implements the stats selection algorithm[1] for receivers. (This is similar to RTCRtpSender.getStats(): https://chromium-review.googlesource.com/c/chromium/src/+/975306) [1] https://w3c.github.io/webrtc-pc/#dfn-stats-selection-algorithm Bug: 680172 Change-Id: I8049a52fcaa3c2bd51e5541c7149d9b3aee57e3d Reviewed-on: https://chromium-review.googlesource.com/976121 Commit-Queue: Henrik Boström <hbos@chromium.org> Reviewed-by: Taylor Brandstetter <deadbeef@chromium.org> Cr-Commit-Position: refs/heads/master@{#546801} 
diff --git a/webrtc/RTCPeerConnection-track-stats.https.html b/webrtc/RTCPeerConnection-track-stats.https.html index 04d4ded..c6c8ce3 100644 --- a/webrtc/RTCPeerConnection-track-stats.https.html +++ b/webrtc/RTCPeerConnection-track-stats.https.html 
@@ -424,6 +424,52 @@  'senderReport should contain remote-candidate stats');  }, 'RTCRtpSender.getStats() contains only outbound-rtp and related stats');   + promise_test(async function() { + const caller = new RTCPeerConnection(); + const callee = new RTCPeerConnection(); + let [tracks, streams] = await getUserMediaTracksAndStreams(2); + let sender = caller.addTrack(tracks[0], streams[0]); + callee.addTrack(tracks[1], streams[1]); + exchangeIceCandidates(caller, callee); + await doSignalingHandshake(caller, callee); + await onIceConnectionStateCompleted(caller); + let receiver = caller.getReceivers()[0]; + + // Obtain inbound and outbound RTP stream stats on a full stats report. + let fullReport = await caller.getStats(); + let outboundTrackStats = findStatsByTypeAndId( + fullReport, 'track', sender.track.id); + let outboundStats = findStatsByTypeAndMember( + fullReport, 'outbound-rtp', 'trackId', outboundTrackStats.id); + assert_true(outboundStats != null, 'Has stats for outbound RTP stream'); + let inboundTrackStats = findStatsByTypeAndId( + fullReport, 'track', receiver.track.id); + let inboundStats = findStatsByTypeAndMember( + fullReport, 'inbound-rtp', 'trackId', inboundTrackStats.id); + assert_true(inboundStats != null, 'Has stats for inbound RTP stream'); + + // Perform stats selection algorithm with receiver selector. The result + // should contain the inbound-rtp but not the outbound-rtp. + let receiverReport = await receiver.getStats(); + assert_true(receiverReport.has(inboundStats.id)); + assert_false(receiverReport.has(outboundStats.id)); + + // Validate the stats graph, ensuring all stats objects are reachable and + // valid from the outbound-rtp stats. + validateStatsGraph(receiverReport, receiverReport.get(inboundStats.id)); + // Ensure that the stats graph contains some expected dictionaries. + assert_equals(findStatsOfType(receiverReport, 'track').length, 1, + 'receiverReport should contain track stats'); + assert_equals(findStatsOfType(receiverReport, 'transport').length, 1, + 'receiverReport should contain transport stats'); + assert_equals(findStatsOfType(receiverReport, 'candidate-pair').length, 1, + 'receiverReport should contain candidate-pair stats'); + assert_equals(findStatsOfType(receiverReport, 'local-candidate').length, 1, + 'receiverReport should contain local-candidate stats'); + assert_equals(findStatsOfType(receiverReport, 'remote-candidate').length, 1, + 'receiverReport should contain remote-candidate stats'); + }, 'RTCRtpReceiver.getStats() contains only inbound-rtp and related stats'); +  // Helpers.    function findStatsByTypeAndId(report, type, identifier) { 
diff --git a/webrtc/RTCRtpReceiver-getStats.html b/webrtc/RTCRtpReceiver-getStats.html deleted file mode 100644 index c30c961..0000000 --- a/webrtc/RTCRtpReceiver-getStats.html +++ /dev/null 
@@ -1,54 +0,0 @@ -<!doctype html> -<meta charset=utf-8> -<title>RTCRtpReceiver.prototype.getStats</title> -<script src="/resources/testharness.js"></script> -<script src="/resources/testharnessreport.js"></script> -<script src="dictionary-helper.js"></script> -<script src="RTCStats-helper.js"></script> -<script> - 'use strict'; - - // Test is based on the following editor draft: - // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html - // https://w3c.github.io/webrtc-stats/archives/20170614/webrtc-stats.html - - // The following helper function is called from RTCStats-helper.js - // validateStatsReport - // assert_stats_report_has_stats - - /* - 5.3. RTCRtpReceiver Interface - interface RTCRtpReceiver { - Promise<RTCStatsReport> getStats(); - ... - }; - - getStats - 1. Let selector be the RTCRtpReceiver object on which the method was invoked. - 2. Let p be a new promise, and run the following steps in parallel: - 1. Gather the stats indicated by selector according to the stats selection - algorithm. - 2. Resolve p with the resulting RTCStatsReport object, containing the - gathered stats. - 3. Return p. - - 8.5. The stats selection algorithm - 4. If selector is an RTCRtpReceiver, gather stats for and add the following objects - to result: - - All RTCInboundRTPStreamStats objects corresponding to selector. - - All stats objects referenced directly or indirectly by the RTCInboundRTPStreamStats - added. - */ - - promise_test(() => { - const pc = new RTCPeerConnection(); - const { receiver } = pc.addTransceiver('audio'); - - return receiver.getStats() - .then(statsReport => { - validateStatsReport(statsReport); - assert_stats_report_has_stats(statsReport, ['inbound-rtp']); - }); - }, 'receiver.getStats() should return stats report containing inbound-rtp stats'); - -</script> 
diff --git a/webrtc/RTCRtpReceiver-getStats.https.html b/webrtc/RTCRtpReceiver-getStats.https.html new file mode 100644 index 0000000..f36c859 --- /dev/null +++ b/webrtc/RTCRtpReceiver-getStats.https.html 
@@ -0,0 +1,72 @@ +<!doctype html> +<meta charset=utf-8> +<title>RTCRtpReceiver.prototype.getStats</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="RTCPeerConnection-helper.js"></script> +<script src="dictionary-helper.js"></script> +<script src="RTCStats-helper.js"></script> +<script> + 'use strict'; + + // Test is based on the following editor draft: + // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html + // https://w3c.github.io/webrtc-stats/archives/20170614/webrtc-stats.html + + // The following helper functions are called from RTCPeerConnection-helper.js: + // doSignalingHandshake + + // The following helper function is called from RTCStats-helper.js + // validateStatsReport + // assert_stats_report_has_stats + + /* + 5.3. RTCRtpReceiver Interface + interface RTCRtpReceiver { + Promise<RTCStatsReport> getStats(); + ... + }; + + getStats + 1. Let selector be the RTCRtpReceiver object on which the method was invoked. + 2. Let p be a new promise, and run the following steps in parallel: + 1. Gather the stats indicated by selector according to the stats selection + algorithm. + 2. Resolve p with the resulting RTCStatsReport object, containing the + gathered stats. + 3. Return p. + + 8.5. The stats selection algorithm + 4. If selector is an RTCRtpReceiver, gather stats for and add the following objects + to result: + - All RTCInboundRTPStreamStats objects corresponding to selector. + - All stats objects referenced directly or indirectly by the RTCInboundRTPStreamStats + added. + */ + + promise_test(async () => { + const caller = new RTCPeerConnection(); + const callee = new RTCPeerConnection(); + const { receiver } = caller.addTransceiver('audio'); + + await doSignalingHandshake(caller, callee); + const statsReport = await receiver.getStats(); + validateStatsReport(statsReport); + assert_stats_report_has_stats(statsReport, ['inbound-rtp']); + }, 'receiver.getStats() via addTransceiver should return stats report containing inbound-rtp stats'); + + promise_test(async () => { + const caller = new RTCPeerConnection(); + const callee = new RTCPeerConnection(); + const stream = await navigator.mediaDevices.getUserMedia({audio:true}); + const [track] = stream.getTracks(); + caller.addTrack(track, stream); + + await doSignalingHandshake(caller, callee); + const receiver = callee.getReceivers()[0]; + const statsReport = await receiver.getStats(); + validateStatsReport(statsReport); + assert_stats_report_has_stats(statsReport, ['inbound-rtp']); + }, 'receiver.getStats() via addTrack should return stats report containing inbound-rtp stats'); + +</script>